package com.dang.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dang.edu.dao.UserDao;
import com.dang.edu.entity.User;
import com.dang.edu.model.bo.LoginDto;
import com.dang.edu.model.bo.RegisterDto;
import com.dang.edu.model.vo.R;
import com.dang.edu.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2023-08-17 17:31:27
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao dao;

    @Override
    public R register(RegisterDto dto) {
        if (dto!=null) {
            LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(User::getName,dto.getName()).or().eq(User::getPassword,dto.getPassword());
            wrapper.last(" limit 1 ");
            if (dao.selectOne(wrapper)==null){
                User user=new User();
                BeanUtils.copyProperties(dto,user);
                if(dao.insert(user)>0){
                    return R.ok();
                }
            }else {
                return R.fail("亲，昵称或手机号已存在！");
            }
        }
        return R.fail("亲，昵称或手机号已存在！");
    }

    @Override
    public R login(LoginDto dto) {
        return null;
    }
}

